package com.liuxinlong.modules.patent.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.PatentProductClass;
import com.liuxinlong.modules.patent.controller.request.QueryPatentDepartmentReq;
import com.liuxinlong.modules.patent.controller.request.UpdatePatentProductClassReq;
import com.liuxinlong.modules.patent.service.PatentProductClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 专利产品品类控制层
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2023-10-07
 */
@RestController
@RequestMapping("/patent-product")
public class PatentProductClassController {

    @Autowired
    private PatentProductClassService patentProductClassService;

    /**
     * 分页查询专利产品品类信息
     *
     * @param req 请求信息
     * @return 专利产品品类信息列表
     */
    @PostMapping("page")
    @LogAnnotation(value ="分页查询",business = LogBusinessConstants.PATENT_PRODUCT_CLASS,operateType = LogOperateConstants.OPERATE_QUERY)
    public BaseResp pageProductClassInfo(@RequestBody QueryPatentDepartmentReq req) {
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("startNum", req.getStartNum());
        queryMap.put("pageSize", req.getPageSize());
        queryMap.put("name", req.getName());
        List<Map<String, Object>> dataList = patentProductClassService.pageProductClassInfo(queryMap);
        int total = patentProductClassService.countProductClass(queryMap);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("分页查询专利产品品类信息成功");
        resp.setDataList(dataList);
        resp.setTotalNum(total);
        return resp;
    }

    /**
     * 新增专利产品品类信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("add")
    @LogAnnotation(value ="新增专利产品品类信息",business = LogBusinessConstants.PATENT_PRODUCT_CLASS,operateType = LogOperateConstants.OPERATE_ADD)
    public BaseResp addProductClassInfo(@RequestBody UpdatePatentProductClassReq req) {
        PatentProductClass PatentProductClass = new PatentProductClass();
        PatentProductClass.setName(req.getName());
        PatentProductClass.setPatentEngineer(req.getPatentEngineer());
        PatentProductClass.setRemark(req.getRemark());
        patentProductClassService.addProductClassInfo(PatentProductClass);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("新增专利产品品类信息成功");
        return resp;
    }

    /**
     * 修改专利产品品类信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("update")
    @LogAnnotation(value ="修改专利产品品类信息",business = LogBusinessConstants.PATENT_PRODUCT_CLASS,operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateProductClassInfo(@RequestBody UpdatePatentProductClassReq req) {
        PatentProductClass PatentProductClass = new PatentProductClass();
        PatentProductClass.setId(req.getId());
        PatentProductClass.setName(req.getName());
        PatentProductClass.setPatentEngineer(req.getPatentEngineer());
        PatentProductClass.setRemark(req.getRemark());
        patentProductClassService.updateProductClassInfo(PatentProductClass);
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改专利产品品类信息成功");
        return resp;
    }

    /**
     * 删除专利产品品类信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("delete")
    @LogAnnotation(value ="删除专利产品品类信息",business = LogBusinessConstants.PATENT_PRODUCT_CLASS,operateType = LogOperateConstants.OPERATE_DELETE)
    public BaseResp deleteProductClassInfo(@RequestBody BaseDeleteReq req) {
        patentProductClassService.deleteProductClassInfo(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("删除专利产品品类信息成功");
        return resp;
    }

    /**
     * 修改专利产品品类状态信息
     *
     * @param req 请求信息
     * @return 成功标识
     */
    @PostMapping("status")
    @LogAnnotation(value ="修改专利产品品类状态信息",business = LogBusinessConstants.PATENT_PRODUCT_CLASS,operateType = LogOperateConstants.OPERATE_MODIFY)
    public BaseResp updateProductClassStatus(@RequestBody BaseDeleteReq req) {
        patentProductClassService.updateProductClassStatus(req.getId());
        BaseResp resp = new BaseResp();
        resp.setRetMessage("修改专利产品品类状态信息成功");
        return resp;
    }
}
